#include <iostream>
using namespace std;


int find(int *f,int x){
	if(f[x] == x) return x;
	return f[x] = find(f,f[x]);
}



int main(){
	int n,m,ans=0;
	cin>>n>>m;
	int f[(n+5)*2];
	for(int i=0;i<n*2+10;i++){
		f[i] = i;
	}
	for(int i=0;i<m;i++){
		int x,y;
		char opt;
		cin>>opt>>x>>y;
		x--;
		y--;
		int fx1=find(f,x),fx2=find(f,x+n);
		int fy1=find(f,y),fy2=find(f,y+n);
		if(opt == 'F'){
			f[fx1] = fy1;
//			f[fx2] = fy2;
		}
		else{
			f[fy2] = fx1;
			f[fx2] = fy1;
		}
	}
	for(int i=0;i<n;i++){
		if(find(f,f[i]) == i)
			ans++; 
	}
	cout<<ans;
}
